/*
 * Project:     My Project Work, Copyright (C) 2011
 * Created at:  24.07.2011
 */
package de.myprojectwork.common.util;

import sun.reflect.Reflection;

/**
 *
 * @author Chris Holdschuh
 */
public class Logger {
    
    private static boolean isDebugMode;

    private Logger() {
        isDebugMode = false;
    }
    
    /**
     * Schaltet die Ausgabe von Debug-Nachrichten ein (true) oder aus (false).
     * @param b true oder false
     */
    public static void setDebugMode(boolean b) {
        isDebugMode = b;
    }

    /**
     * @see org.apache.log4j.Category#debug(java.lang.Object)
     */
    public static void debug(Object message) {
        if (isDebugMode) {
            getLogger().debug(message);
        }
    }
    
    /**
     * @see org.apache.log4j.Category#debug(java.lang.Object, java.lang.Throwable)
     */
    public static void debug(Object message, Throwable t) {
        if (isDebugMode) {
            getLogger().debug(message, t);
        }
    }
    
    /**
     * @see org.apache.log4j.Category#info(java.lang.Object)
     */
    public static void info(Object message) {
        getLogger().info(message);
    }
    
    /**
     * @see org.apache.log4j.Category#info(java.lang.Object, java.lang.Throwable)
     */
    public static void info(Object message, Throwable t) {
        getLogger().info(message, t);
    }
    
    /**
     * @see org.apache.log4j.Category#warn(java.lang.Object)
     */
    public static void warn(Object message) {
        getLogger().warn(message);
    }
    
    /**
     * @see org.apache.log4j.Category#warn(java.lang.Object, java.lang.Throwable)
     */
    public static void warn(Object message, Throwable t) {
        getLogger().warn(message, t);
    }
    
    /**
     * @see org.apache.log4j.Category#error(java.lang.Object)
     */
    public static void error(Object message) {
        getLogger().error(message);
    }
    
    /**
     * @see org.apache.log4j.Category#error(java.lang.Object, java.lang.Throwable)
     */
    public static void error(Object message, Throwable t) {
        getLogger().error(message, t);
    }
    
    /**
     * @see org.apache.log4j.Category#fatal(java.lang.Object)
     */
    public static void fatal(Object message) {
        getLogger().fatal(message);
    }
    
    /**
     * @see org.apache.log4j.Category#fatal(java.lang.Object, java.lang.Throwable)
     */
    public static void fatal(Object message, Throwable t) {
        getLogger().fatal(message, t);
    }

    @SuppressWarnings("unchecked")
    private static org.apache.log4j.Logger getLogger() {
        Class caller = Reflection.getCallerClass(3);
        return org.apache.log4j.Logger.getLogger(caller);
    }
}
